package com.sort;

import java.util.Arrays;

/*
* 冒泡排序
* */
public class Bubble_Sort {

    public static void main(String[] args) {
        int[] arr = {12,3,2,6,321,2};
        new Bubble_Sort().sort(arr);
    }
    public void sort(int[] arr){
        int[] copy = Arrays.copyOf(arr, arr.length);
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - 1 -i; j++) {
                if (copy[j] > copy[j+1]){
                    int temp = copy[j];
                    copy[j] = copy[j+1];
                    copy[j+1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(copy));
    }
}
